@extends('admin.layout')

@section('title', '管理友情链接')

@section('body')
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">管理友情链接</div>
                    <div class="layui-card-body">
                        <table class="layui-table" lay-size="lg" lay-data="{url:'/admin/link/list', id:'listbox', even:true}">
                            <thead>
                            <tr>
                                <th lay-data="{field:'id', width:80, align:'center'}">ID</th>
                                <th lay-data="{field:'link_name', width:200}">链接名称</th>
                                <th lay-data="{field:'link_url', minWidth:200, templet:'#linkUrl'}">链接地址</th>
                                <th lay-data="{field:'list_order', width:90, align:'center', sort:true}">排序</th>
                                <th lay-data="{align:'center', width:220, toolbar:'#actionBar'}">操作</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/html" id="linkUrl">
        <a href="@{{= d.link_url }}" target="_blank">@{{= d.link_url }}</a>
    </script>
    <script type="text/html" id="actionBar">
        <button class="layui-btn layui-btn-normal" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</button>
        <button class="layui-btn layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</button>
    </script>
    <script>
        layui.use(['layer', 'table'], function () {
            var $ = layui.$;
            var layer = layui.layer;
            var table = layui.table;

            table.on('tool', function (obj) {
                if (obj.event === 'edit') {
                    window.parent.layer.load(1);
                    location.href = '/admin/link/edit?id=' + obj.data.id;
                }
                if (obj.event === 'del') {
                    layer.confirm('确定删除友情链接【' + obj.data.link_name + '】吗？', {
                        icon: 3
                    }, function () {
                        $.post('/admin/link/del', {id: obj.data.id}, function (res) {
                            if (res.code === 0) {
                                layer.msg(res.msg, {
                                    icon: 1,
                                    time: 1000
                                }, function () {
                                    table.reload('listbox');
                                });
                            } else {
                                layer.msg(res.msg, {icon: 5});
                            }
                        }, 'json');
                    });
                }
            });
        });
    </script>
@endsection
